package net.hn.hnms.biz.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.project.domain.ProjectInfo;
import net.hn.hnms.biz.project.request.ProjectInfoReq;
import net.hn.hnms.biz.project.vo.ProjectInfoVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ProjectInfoMapper extends BaseMapper<ProjectInfo> {
    @Update("<script>" +
            " update  project_info set  del_flag = '1' " +
            " where project_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteByIds(@Param("list") List<String> list);

    @Update("<script>" +
            " update  project_budget set  del_flag = '1' " +
            " where project_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteBudgetByIds(@Param("list") List<String> list);

    @Select("<script>" +
            " SELECT " +
            " pi.project_id projectId,pi.project_code projectCode,pi.project_name projectName,pi.project_date projectDate, " +
            " pi.start_date startDate,pi.end_date endDate,pi.region,pi.project_address projectAddress,pi.project_type projectType, " +
            " pi.project_state projectState,pi.supervise_department superviseDepartment,pi.supervise_person supervisePerson, " +
            " pi.project_initiator projectInitiator,pi.project_department projectDepartment,pi.project_phone projectPhone,pi.total_amount totalAmount " +
            " FROM " +
            " project_info pi " +
            " where pi.del_flag = '0' " +
            " <if test='query.projectCode!= null and query.projectCode!= \"\" '>"+
            " and pi.project_code = #{query.projectCode} " +
            " </if>"+
            " <if test='query.projectName!= null and query.projectName!= \"\" '>"+
            " and pi.project_name = #{query.projectName} " +
            " </if>"+
            " <if test='query.projectInitiator!= null and query.projectInitiator!= \"\" '>"+
            " and pi.project_initiator = #{query.projectInitiator} " +
            " </if>"+
            " <if test='query.projectInitiator!= null and query.projectInitiator!= \"\" '>"+
            " and pi.project_initiator = #{query.projectInitiator} " +
            " </if>"+
            "</script>")
    Page<ProjectInfoVo> selectPageList(Page<Object> build, @Param("query") ProjectInfoReq query);

}
